# Maintainer: Konstantin Gizdov <arch at kge dot pw>
# Maintainer: Torsten Keßler <tpkessler at archlinux dot org>

_pkgbase='intel-oneapi-compiler-dpcpp'
_pkgname="${_pkgbase}-cpp"
pkgbase="${_pkgname}-runtime"
pkgname=("${_pkgname}-runtime" "${_pkgname}-runtime-libs")
pkgver='2023.0.0'
_debpkgrel='25370'
pkgrel=5
_pkgdesc="Intel oneAPI Data Parallel C++ compiler"
arch=('loong64' 'x86_64')
url='https://software.intel.com/content/www/us/en/develop/tools/oneapi.html'
license=("custom")
source=("https://apt.repos.intel.com/oneapi/pool/main/${pkgname}-${pkgver}-${pkgver}-${_debpkgrel}_amd64.deb"
        "https://apt.repos.intel.com/oneapi/pool/main/${_pkgname}-common-${pkgver}-${pkgver}-${_debpkgrel}_all.deb"
        "https://apt.repos.intel.com/oneapi/pool/main/${_pkgbase}-eclipse-cfg-${pkgver}-${_debpkgrel}_all.deb"
        "https://apt.repos.intel.com/oneapi/pool/main/intel-oneapi-icc-eclipse-plugin-cpp-${pkgver}-${pkgver}-${_debpkgrel}_all.deb")
b2sums=('e330b6546a2fc508d03ffde75f7be5aa7e4a8f900536145603503fc8477a6e24259fe66d8766149311b8efdbfaa2ac4032f5b989cc85e65b1a338da686a944eb'
        'a5f10e365a11869b43a8caecd08d334469c0c22931e9e334ae3aa265cd542bcd191a77bdebf3be060596a8aabcb6c4f5a27f047298d5bdd0c00d014a2df7e6e1'
        '04881427864d13e353f8cdeedbf048fc5bc3ed0fe643293c78093d6640b8a3917e07400f4bdd12c16c9e5dd8c91bf8fb4fc13d3d60cbcffbaea1308a133a4c5d'
        '048fc7d119e77cf8385fe206992a920911e777e070ff24041f1da5a919c01454ba96589be08c74c492a834d3b59c225a82b5568b489dd20e2c030a730f68fa73')
noextract=(
    "${pkgname}-${pkgver}-${pkgver}-${_debpkgrel}_amd64.deb"
    "${_pkgname}-common-${pkgver}-${pkgver}-${_debpkgrel}_all.deb"
    "${_pkgbase}-eclipse-cfg-${pkgver}-${_debpkgrel}_all.deb"
    "intel-oneapi-icc-eclipse-plugin-cpp-${pkgver}-${pkgver}-${_debpkgrel}_all.deb"
)

build() {
    mkdir "${_pkgbase}-${pkgver}"
    ar x "${srcdir}/${pkgname}-${pkgver}-${pkgver}-${_debpkgrel}_amd64.deb"
	tar xvf data.tar.xz -C "${_pkgbase}-${pkgver}"
    rm data.tar.xz

    ar x "${srcdir}/${_pkgname}-common-${pkgver}-${pkgver}-${_debpkgrel}_all.deb"
    tar xvf data.tar.xz -C "${_pkgbase}-${pkgver}"
    rm data.tar.xz

    ar x "${srcdir}/${_pkgbase}-eclipse-cfg-${pkgver}-${_debpkgrel}_all.deb"
    tar xvf data.tar.xz -C "${_pkgbase}-${pkgver}"
    rm data.tar.xz

    ar x "${srcdir}/intel-oneapi-icc-eclipse-plugin-cpp-${pkgver}-${pkgver}-${_debpkgrel}_all.deb"
    tar xvf data.tar.xz -C "${_pkgbase}-${pkgver}"
    rm data.tar.xz

    mkdir "${_pkgbase}-${pkgver}-libs"
    local _lib_path="/opt/intel/oneapi/compiler/${pkgver}/linux"
    install -d "${_pkgbase}-${pkgver}-libs/${_lib_path}/lib"
    cd "${_pkgbase}-${pkgver}/${_lib_path}/lib"
    local _lib
    for _lib in libpi_level_zero.so libsycl*; do
        mv "${_lib}" "${srcdir}/${_pkgbase}-${pkgver}-libs/${_lib_path}/lib"
    done
}

package_intel-oneapi-compiler-dpcpp-cpp-runtime-libs() {
    depends=('intel-oneapi-compiler-shared-runtime-libs' 'intel-oneapi-tbb' 'intel-oneapi-common')
    conflicts=('intel-oneapi-basekit')
    pkgdesc="${_pkgdesc}: Minimal runtime libraries"

    cp -a "${srcdir}/${_pkgbase}-${pkgver}-libs/opt" "${pkgdir}"

    # allow libs to be found
    local _lib_path='/opt/intel/oneapi/compiler'
    local _ldso_conf="${pkgdir}"/etc/ld.so.conf.d
    install -d "${_ldso_conf}"
    echo "${_lib_path}/latest/linux/lib" > "${_ldso_conf}/${pkgname}.conf"

    install -d "${pkgdir}"/usr/share/licenses/"${pkgname}"
    ln -s /usr/share/licenses/intel-oneapi "${pkgdir}"/usr/share/licenses/"${pkgname}"/oneapi
}

package_intel-oneapi-compiler-dpcpp-cpp-runtime() {
    depends=('intel-oneapi-compiler-shared-runtime' 'intel-oneapi-compiler-dpcpp-cpp-runtime-libs' 'intel-oneapi-common')
    provides=('intel-oneapi-compiler-dpcpp-cpp-common' 'intel-oneapi-compiler-dpcpp-eclipse-cfg' 'intel-oneapi-icc-eclipse-plugin-cpp')
    conflicts=('intel-oneapi-basekit')
    pkgdesc="${_pkgdesc}: Full runtime libraries and header files"

    cp -a "${srcdir}/${_pkgbase}-${pkgver}/opt" "${pkgdir}"

    # allow libs to be found
    local _lib_path='/opt/intel/oneapi/compiler'
    local _ldso_conf="${pkgdir}"/etc/ld.so.conf.d
    install -d "${_ldso_conf}"
    echo "${_lib_path}/latest/linux/lib/x64" >> "${_ldso_conf}/${pkgname}.conf"

    install -d "${pkgdir}"/usr/share/licenses/"${pkgname}"
    ln -s /usr/share/licenses/intel-oneapi "${pkgdir}"/usr/share/licenses/"${pkgname}"/oneapi
}
